import areaData from './area.json'

// 转换数据格式
const convertData = (data: any) => {
    return data.map((item: any) => {
        console.log('转换数据:', item.name, item.code)
        return {
            label: item.name,
            value: item.code?.toString() || '',
            children: item.children ? convertData(item.children) : undefined
        }
    })
}

// 确保数据格式正确
const processedData = convertData(areaData).map(province => {
    if (province.children) {
        province.children = province.children.map(city => {
            if (city.children) {
                // 只保留区县级数据
                const validAreas = city.children.filter(area => {
                    const isValid = area.value && area.value.length === 6
                    if (!isValid) {
                        console.log('过滤掉无效区县:', area.label, area.value)
                    }
                    return isValid
                })
                city.children = validAreas
                console.log(`城市 ${city.label} 的有效区县数量:`, validAreas.length)
            }
            return city
        })
    }
    return province
})

console.log('处理后的省份数量:', processedData.length)
export default processedData 